const express=require('express');
const router=express.Router();
const contactModel=require('../models/contact.js');
const path=require('path');
const ContactController=require('../controllers/contactController.js');


/* 完成图片上传功能 */
const multer=require('multer');
// const upload=multer({desk:path.join(__dirname,'../public/uploads')})
const storage=multer.diskStorage({
    destination:function (req,file,cb) {
        cb(null,path.join(__dirname,'../public/uploads'))
    },
    filename:function (req,file,cb) {
        const uniqueSuffix=Date.now()+'-'+Math.round(Math
            .random()*1E9);
        // path.extname(file.originalname) 可以获取文件的扩展名
        cb(null,file.fieldname+'-'+uniqueSuffix+path.extname(file.originalname));
    }
})
const upload=multer({storage:storage});

router.post('/contact/store',upload.single('companyPic'), ContactController.putInStore);

router.get('/contact', ContactController.getContact);
module.exports=router;